package com.swa99ylum.pjv.sample.s04_others.s0410;

import java.util.Date;
import java.util.List;

import com.alibaba.fastjson.JSONPath;
import com.swa99ylum.pjv.sample.FileUtils;

public class PerformanceTest {

	public static void main(String[] args) {
		long begin = new Date().getTime(); 
		PerformanceTest p = new PerformanceTest();
		p.foo();
		
		long end = new Date().getTime();
		System.out.println("总耗时：" + (end-begin));
	}
	
	public void foo() {
		//step1、获取 json
//		String filePath = Test1.class.getResource("json_0410_30.txt").getPath();
		String filePath = Test1.class.getResource("json_0410.txt").getPath();
		
		String json = null;
		try {
			json = FileUtils.getFileContent(filePath);
		} catch (Exception e) {
			System.err.println("从 文件中，读取 json 有误");
		}
		
		//step2、解析 json
		@SuppressWarnings("unchecked")
		List<String> aaa1 = (List<String>) JSONPath.read(json, "$.data.request");
		String[] aaa2 = new String[]{"matnr", "werks", "zdate", "labst", "speme"};
		
		for(int i=0; i<=aaa1.size()-1; i++) {
			
			for (String string : aaa2) {
				long begin = new Date().getTime();
				
				String path = "$.data.request["+i+"]." + string;
				System.out.println(path + " => " + JSONPath.read(json, path));
				
				long end = new Date().getTime();
				System.out.println(end-begin);
			}
			
		}
	
	}
}
